<?php
/**
 * 文件名：app.mod.php
 * 版本号：1.0
 * 作者：mrasong
 * 功能描述：应用模块
 */
if(!defined('IN_JISHIGOU'))
{
    exit('invalid request');
}

class ModuleObject extends MasterObject{
	var $ID = 0;

	function ModuleObject($config)
	{
		$this->MasterObject($config);
		if(isset($this->Get['id'])){
			$this->ID = (int)$this->Get['id'];
		}elseif(isset($this->Post['id'])){
			$this->ID = (int)$this->Post['id'];
		}	
		$this->Execute();
	}

	function Execute()
	{
		ob_start();
		
		switch($this->Code)
		{
			case "play":
				$this->play();
				break;
			case "cate":
				$this->cate();
				break;
			default:
				$this->Main();
				break;
		}
		$Contents=ob_get_clean();
		$this->ShowBody($Contents);
	}

	function Main()
	{	
		$sql = "select * from `".TABLE_PREFIX."apps` order by ID desc limit 12";
		$query = $this->DatabaseHandler->Query($sql);
		$apps = array();
		while ($row = $query->GetRow()){
			$apps[] = $row;
		}
		include(ROOT_PATH . './templates/app/app_index.php');
	}
	
	function cate(){
		$sql = "select * from `".TABLE_PREFIX."apps` where category='".base64_decode($this->Get['id'])."' order by ID desc";
		$query = $this->DatabaseHandler->Query($sql);
		$apps = array();
		while ($row = $query->GetRow()){
			$apps[] = $row;
		}
		include(ROOT_PATH . './templates/app/app_category.php');
	}
	
	function play(){
		$sql = "select * from `".TABLE_PREFIX."apps` where id=".$this->Get['id'];
		$query = $this->DatabaseHandler->Query($sql);
		$info = $query->GetRow();
		
		if( preg_match("/.swf$/i",trim($info['url']) ) ){
			$info['type'] = "flash";
		}else{
			$info['type'] = "iframe";
		}
			
		include(ROOT_PATH . './templates/app/app_play.php');
	}
}

?>
